<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>女性图片生成视频</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"], input[type="number"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }
        input[type="file"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
        }
        button:hover {
            background-color: #0056b3;
        }
        .flash-messages {
            margin-bottom: 20px;
        }
        .flash-success {
            background-color: #d4edda;
            color: #155724;
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #c3e6cb;
        }
        .flash-error {
            background-color: #f8d7da;
            color: #721c24;
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #f5c6cb;
        }
        .navigation {
            margin-top: 30px;
            text-align: center;
        }
        .nav-link {
            display: inline-block;
            margin: 10px;
            color: #007bff;
            text-decoration: none;
            padding: 10px 20px;
            border: 1px solid #007bff;
            border-radius: 5px;
        }
        .nav-link:hover {
            background-color: #007bff;
            color: white;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 5px;
            display: none;
        }
        .success {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        .note {
            background-color: #fff3cd;
            border: 1px solid #ffeaa7;
            border-radius: 5px;
            padding: 10px;
            margin: 10px 0;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>女性图片生成视频</h1>
        
        <div class="note">
            <p><strong>功能说明：</strong></p>
            <ul>
                <li>上传女性图片，系统将根据图片生成指定数量的视频</li>
                <li>每个视频中女性会更换不同风格的妆造（包括服装、鞋子、配饰等）</li>
                <li>场景为足球相关的现场（如足球场、观众席等）</li>
                <li>视频中会显示"Nhấn vào follow để xem bóng đá cùng tôi"（点击关注，一起看足球）文本</li>
                <li>视频时长：10秒</li>
                <li>视频分辨率：480*832（竖屏）</li>
            </ul>
        </div>
        
        <!-- 显示闪现消息 -->
        <div class="flash-messages">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <div class="flash-{{ category }}">{{ message }}</div>
                    {% endfor %}
                {% endif %}
            {% endwith %}
        </div>
        
        <form id="femaleVideoForm" enctype="multipart/form-data">
            <div class="form-group">
                <label for="image_file">选择图片:</label>
                <input type="file" id="image_file" name="image_file" accept="image/*" required>
            </div>
            
            <div class="form-group">
                <label for="count">生成数量:</label>
                <input type="number" id="count" name="count" min="1" max="10" value="{{ cached_inputs.count or 1 }}" required>
            </div>
            
            <div class="form-group">
                <label for="output_dir">输出目录:</label>
                <input type="text" id="output_dir" name="output_dir" value="{{ cached_inputs.output_dir or 'output/female_videos' }}" required>
            </div>
            
            <button type="submit">生成视频</button>
        </form>
        
        <div id="result" class="result"></div>
        
        <div class="navigation">
            <a href="{{ url_for('index') }}" class="nav-link">← 返回主页</a>
        </div>
    </div>

    <script>
        document.getElementById('femaleVideoForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const resultDiv = document.getElementById('result');
            
            // 显示处理中消息
            resultDiv.className = 'result';
            resultDiv.innerHTML = '<p>正在处理，请稍候...</p>';
            resultDiv.style.display = 'block';
            
            // 禁用提交按钮
            const submitButton = this.querySelector('button');
            submitButton.disabled = true;
            submitButton.textContent = '处理中...';
            
            // 发送请求
            fetch('/female-portrait-video-process', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 重定向到任务状态页面
                    window.location.href = '/female-video-task/' + data.task_id;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = `<h3>处理失败</h3><p>${data.error}</p>`;
                    submitButton.disabled = false;
                    submitButton.textContent = '生成视频';
                }
            })
            .catch(error => {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = `<h3>处理失败</h3><p>${error.message}</p>`;
                submitButton.disabled = false;
                submitButton.textContent = '生成视频';
            });
        });
    </script>
</body>
</html>